import { Component, OnInit } from '@angular/core';

import { MonitorBrandComponentService } from './monitor.brand.component.service';

import { BrandBase } from '../../brand/brand.base';


import { Util } from '../../../utils/util';


@Component({
  selector: 'monitor-brand',
  templateUrl: './monitor.brand.component.html',
  styleUrls: ['./monitor.brand.component.css'],
  providers: [MonitorBrandComponentService]
})

export class MonitorBrandComponent extends BrandBase {


  constructor(public service: MonitorBrandComponentService, public util: Util) {
    // 继承
    super(util, service);
    console.log(this);
    this.getHttp(this.param);
  }

  // 参数
  param: any = {
    type: 3,
    start: 0,
    rows: 1000,
    sort: '',
    sortType: ''
  };

  p: number = 0;


  // ngOnInit(){
  //   // this.util.columnHiddenHandel(this.columns,this.timeType);

  // }
  addView: boolean = false;
  add() {
    this.addView = !this.addView;

    if (this.addView == false) {
      this.getHttp(this.param);
    }
  }

  sortChange(sort) {
    console.log(sort);

    let _sort: string = sort.sort;

    let _sortType: string = sort.sortType;

    if (_sortType == 'desc') {

      this.vm.table.brands.sort((a, b) => {
        return a[_sort] < b[_sort];
      });

    } else {

      this.vm.table.brands.sort((a, b) => {
        return a[_sort] > b[_sort];
      });

    }

  }

  export() {


    let dim = ['date', 'categoryName', 'categoryId', 'brandName', 'sellMoney', 'sellAmount', 'monthSellMoney', 'monthSellAmount', 'productNum', 'shopNum', 'tsellMoney', 'tsellAmount', 'monthTSellMoney', 'monthTSellAmount', 'tproductNum', 'tshopNum', 'thksellMoney', 'thksellAmount', 'monthThkSellMoney', 'monthThkSellAmount', 'thkproductNum', 'thkshopNum', 'gsellMoney', 'gsellAmount', 'monthGSellMoney', 'monthGSellAmount', 'gproductNum', 'gshopNum', 'csellMoney', 'csellAmount', 'monthCSellMoney', 'monthCSellAmount', 'cproductNum', 'cshopNum'];

    let dimText = ['时间', '类目', '类目id', '品牌名', '日销售额', '日销售量', '近30天销售额', '近30天销售量', '宝贝数', '店铺数', '天猫日销售额', '天猫日销售量', '天猫近30天销售额', '天猫近30天销售量', '天猫宝贝数', '天猫店铺数', '天猫国际日销售额', '天猫国际日销售量', '天猫国际近30天销售额', '天猫国际近30天销售量', '天猫国际宝贝数', '天猫国际店铺数', '全球购日销售额', '全球购日销售量', '全球购近30天销售额', '全球购近30天销售量', '全球购宝贝数', '全球购店铺数', '淘宝日销售额', '淘宝日销售量', '淘宝近30天销售额', '淘宝近30天销售量', '淘宝宝贝数', '淘宝店铺数'];



    let fileName = "全部监控品牌";

    let data = this.util.jsonToArrry(this.vm.table.brands, dim, dimText);

    this.util.export(data, fileName);


  }

  getHttp(param) {

    var res: any = {
      "code": 0, "msg": "成功", "data": {
        "value":
          [
            { "id": "-1\u0001new balance", "date": "2017-12-03 00:00:00", "categoryId": "-1", "categoryName": "/", "categoryLevel": 0, "brandName": "new balance", "sellAmount": 5569, "tsellAmount": 4215, "csellAmount": 1263, "thksellAmount": 21, "gsellAmount": 70, "monthSellAmount": 1039095, "monthTSellAmount": 1002582, "monthCSellAmount": 32778, "monthThkSellAmount": 1068, "monthGSellAmount": 2667, "sellMoney": 1834940.19, "tsellMoney": 1077847.05, "csellMoney": 706854.14, "thksellMoney": 9906.0, "gsellMoney": 40333.0, "monthSellMoney": 3.2061178074E8, "monthTSellMoney": 3.001081916E8, "monthCSellMoney": 1.844366248E7, "monthThkSellMoney": 637228.6, "monthGSellMoney": 1422698.06, "productNum": 7465, "tproductNum": 1787, "cproductNum": 5068, "thkproductNum": 127, "gproductNum": 483, "shopNum": 765, "tshopNum": 35, "cshopNum": 596, "thkshopNum": 12, "gshopNum": 122 }
          ], "count": 1
      }
    };


    this.vm.table.brands = res.data.value;

    this.vm.table.count = res.data.count;


  }



}
